package io.github.hellomaker.domain.strategy.model.entity;

import io.github.hellomaker.types.common.Constants;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

@Data
@Builder
public class StrategyEntity {

    /**
     *抽奖策略ID
     */
    private  Long strategyId;

    /**
     *抽奖策略描述
     */
    private  String strategyDesc;

    /**
     *规则模型，rule配置的模型同步到此表，便于使用
     */
    private  String ruleModels;

    public List<String> listRuleModels() {
        if (StringUtils.isEmpty(ruleModels)) {
            return Collections.emptyList();
        }
        String[] split = ruleModels.split(Constants.SPLIT);
        return Arrays.asList(split);
    }

    public String getRuleWeight() {
        List<String> ruleModelList = listRuleModels();
        for (String ruleModel : ruleModelList) {
            if ("rule_weight".equals(ruleModel)) {
                return ruleModel;
            }
        }
        return null;
    }



}
